<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
// 题目1: 对字符串进行排列组合, 得到所有字符的全排列组合(假设所有字符不重复)
// 函数名：permutation
// 参数：需要排列组合的字符串
// 返回值：字符串的所有排列组合数组
// 例如：permutation("abc") 返回 ["abc", "acb", "bac", "bca", "cab", "cba"]

let permutation =function(str){
    let str1 = [];
    if(str.length <= 1){
        return [str];
    }else{
        for(let i = 0;i<str.length; i++){
            let a = str[i];
            let newstr = str.slice(0,i)+str.slice(i+1 ,str.length);
            let arr = permutation(newstr);

            for(let j =0; j<arr.length ;j++){
                let y = a + arr[j];
                str1.push(y);
            }
        }
    }
    return str1;

}
let k = permutation("abc");
console.log(k);

  
</script>